class StationController:
    def __init__(self, canvas, text_manager):
        self.canvas = canvas
        self.text_manager = text_manager
        self.station_state = "normal"  # normal, emergency, open
        self._create_station()
    
    def _create_station(self):
        """创建站台"""
        # 创建站台矩形
        self.station_rect = self.canvas.create_rectangle(850, 220, 1040, 340, width=2)
        # 在矩形内部创建文本
        self.station_text = self.canvas.create_text(945, 280, text="站台", font=("黑体", 16), fill="black")
    
    def set_emergency_state(self):
        """设置站台门紧急关闭状态"""
        self.station_state = "emergency"
        self.canvas.itemconfig(self.station_rect, fill="yellow")
        text_to_insert = [
            "检测到点击7G站台门",
            "已成功将7G站台设置为紧急关闭状态!"
        ]
        self.text_manager.insert_text_with_delay(text_to_insert)
    
    def cancel_emergency_state(self):
        """取消站台门紧急关闭状态"""
        self.station_state = "normal"
        self.canvas.itemconfig(self.station_rect, fill="white")
        text_to_insert = [
            "检测到点击7G站台门",
            "已成功取消7G站台紧急关闭状态!"
        ]
        self.text_manager.insert_text_with_delay(text_to_insert)
    
    def open_station_door(self):
        """站台门打开"""
        self.station_state = "open"
        self.canvas.itemconfig(self.station_rect, fill="yellow")
        text_to_insert = [
            "检测到点击7G站台门",
            "7G站台门打开!"
        ]
        self.text_manager.insert_text_with_delay(text_to_insert)
    
    def close_station_door(self):
        """站台门关闭"""
        self.station_state = "normal"
        self.canvas.itemconfig(self.station_rect, fill="white")
        text_to_insert = [
            "检测到点击7G站台门",
            "7G站台门关闭!"
        ]
        self.text_manager.insert_text_with_delay(text_to_insert)
    
    def get_station_state(self):
        """获取站台状态"""
        return self.station_state
    
    def is_emergency(self):
        """检查是否处于紧急状态"""
        return self.station_state == "emergency"
    
    def is_door_open(self):
        """检查站台门是否打开"""
        return self.station_state == "open" 